import { FormProps, FormSchema } from '@/components/Table'
import { BasicColumn } from '@/components/Table/src/types/table'
import { pattern } from '@/utils/validate/index'

// 用户列表
export function getUserBasicColumns(): BasicColumn[] {
  return [
    {
      title: '姓名',
      dataIndex: 'userName'
    },
    {
      title: '电子邮箱',
      dataIndex: 'email'
    },
    {
      title: '手机号码',
      dataIndex: 'phoneNumber'
    },
    {
      title: '渠道名称',
      width: 160,
      dataIndex: 'channelName'
    },
    {
      title: '角色',
      width: 420,
      dataIndex: 'rolePermit'
    },
    {
      title: '渠道负责人',
      width: 120,
      dataIndex: 'channelHead'
    },
    {
      title: '创建时间',
      dataIndex: 'createDate'
    },
    {
      title: '状态',
      dataIndex: 'userStatus'
    },
    {
      title: '操作',
      width: 144,
      dataIndex: 'operate'
    }
  ]
}

export function getSearchFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    baseColProps: {
      span: 6,
      md: 10,
      xl: 8,
      xxl: 6
    },
    schemas: [
      {
        field: 'userName',
        label: '姓名',
        component: 'Input',
        componentProps: {
          placeholder: '请输入用户姓名'
        }
      },
      {
        field: 'email',
        label: '邮箱',
        component: 'Input',
        componentProps: {
          placeholder: '请输入用户邮箱'
        }
      },
      {
        field: 'phoneNumber',
        label: '手机号',
        component: 'Input',
        componentProps: {
          placeholder: '请输入用户手机号'
        }
      },
      {
        field: 'channelCode',
        label: '渠道名称',
        component: 'TreeSelect',
        slot: 'channelCode'
      },
      {
        field: 'channelHead',
        label: '渠道负责人',
        component: 'Input',
        componentProps: {
          placeholder: '请输入渠道负责人'
        }
      },
      {
        field: 'userStatus',
        label: '状态',
        component: 'Select',
        componentProps: {
          options: [
            {
              label: '启用',
              value: 0,
              key: 0
            },
            {
              label: '停用',
              value: 1,
              key: 1
            }
          ]
        }
      }
    ]
  }
}

// 用户信息表单
export function getUserFormConfig(): Partial<FormProps> {
  return {
    showActionButtonGroup: false,
    rowProps: {
      gutter: 64
    },
    labelWidth: '100px',
    baseColProps: {
      span: 12,
      style: {
        marginBottom: '4px'
      }
    },
    schemas: [
      {
        field: 'userName',
        component: 'Input',
        label: '姓名',
        required: true
      },
      {
        field: 'email',
        component: 'Input',
        label: '邮箱',
        rules: [
          {
            required: true,
            message: '请输入邮箱'
          },
          {
            pattern: pattern.regexp_email,
            message: '请输入正确的邮箱'
          }
        ]
      },
      {
        field: 'phoneNumber',
        component: 'Input',
        label: '手机号码',
        rules: [
          {
            required: true,
            message: '请输入手机号码'
          },
          {
            pattern: pattern.regexp_cell_phone,
            message: '请输入正确的手机号码'
          }
        ]
      },
      {
        field: 'userAccount',
        component: 'Input',
        required: true,
        label: '登录用户名'
      },
      {
        field: 'channelFlag',
        slot: 'channelFlag',
        component: 'Switch',
        label: '渠道标识',
        required: true,
        defaultValue: '0',
        colProps: {
          span: 24
        },
        componentProps: {
          checkedChildren: '启用',
          unCheckedChildren: '关闭',
          checkedValue: '1',
          unCheckedValue: '0'
        }
      },
      {
        field: 'channelType',
        slot: 'channelType',
        required: true,
        component: 'CheckboxGroup',
        label: '渠道类型',
        ifShow: ({ values }) => {
          return values.channelFlag === '1'
        },
        colProps: {
          span: 24
        }
      },
      {
        field: 'parentChannelCode',
        label: '上级渠道',
        component: 'TreeSelect',
        slot: 'parentChannelCode',
        ifShow: ({ values }) => {
          return values.channelFlag === '1'
        }
      },
      {
        field: 'channelName',
        component: 'Input',
        required: true,
        label: '渠道名称',
        componentProps: {
          maxLength: 64
        },
        ifShow: ({ values }) => {
          return values.channelFlag === '1'
        }
      },
      {
        field: 'channelCode',
        component: 'Input',
        required: true,
        label: '渠道编码',
        componentProps: {
          maxLength: 64
        },
        ifShow: ({ values }) => {
          return values.channelFlag === '1'
        }
      },
      {
        field: 'channelHead',
        component: 'Input',
        label: '渠道负责人',
        componentProps: {
          maxLength: 10,
          placeholder: '请输入对应标普云的销售负责人'
        },
        ifShow: ({ values }) => {
          return values.channelFlag === '1'
        }
      },
      {
        field: 'feeModel',
        component: 'Select',
        label: 'BPai售卖方式',
        ifShow: ({ values }) => {
          return values.channelFlag === '1'
        },
        componentProps: {
          options: [
            {
              label: '按次数计费',
              value: 'SCORE',
              key: 'SCORE'
            },
            {
              label: '按周期计费',
              value: 'CYCLE',
              key: 'CYCLE'
            }
          ]
        }
      },
      {
        field: 'userStatus',
        component: 'Switch',
        label: '用户状态',
        defaultValue: '0',
        required: true,
        colProps: {
          span: 24
        },
        componentProps: {
          checkedChildren: '启用',
          unCheckedChildren: '停用',
          checkedValue: '0',
          unCheckedValue: '1'
        }
      },
      {
        field: 'roleIdList',
        slot: 'roleIdList',
        required: true,
        label: '用户角色',
        component: 'Select'
      }
    ]
  }
}
